Skip to content

Conversation

@nameless-mc
Copy link
Contributor

Why

The dependency relationship between actions[].type and actions[].executableUser was not expressed in
the type system.

In kintone's process management API, actions[].executableUser is required in requests and included in
responses only when actions[].type is "SECONDARY". By expressing this dependency relationship as
type information, we can reduce runtime errors and improve the developer experience.

What

  • Changed ActionForResponse type to a discriminated union, adding a type constraint that makes
    executableUser required only when type="SECONDARY"
  • Changed ActionForParameter type to a discriminated union, adding a type constraint that makes
    executableUser required only when type="SECONDARY"
  • Removed unused ActionType type

How to test

Checklist

  • Read CONTRIBUTING.md
  • Updated documentation if it is required.
  • Added tests if it is required.
  • Passed pnpm lint and pnpm test on the root directory.

@nameless-mc nameless-mc self-assigned this Nov 19, 2025
@nameless-mc nameless-mc requested a review from a team as a code owner November 19, 2025 06:07
@nameless-mc nameless-mc requested review from chihiro-adachi, Copilot and tasshi-me and removed request for a team November 19, 2025 06:07
@github-actions github-actions bot added the pkg: rest-api-client @kintone/rest-api-client label Nov 19, 2025
Copilot finished reviewing on behalf of nameless-mc November 19, 2025 06:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves type safety by expressing the dependency between actions[].type and actions[].executableUser through discriminated unions, ensuring executableUser is required only when type="SECONDARY".

Key Changes:

  • Converted ActionForResponse and ActionForParameter to discriminated unions
  • Made executableUser required for type="SECONDARY" actions
  • Removed the unused ActionType helper type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +92 to +102
} & (
| {
type?: "PRIMARY";
}
| {
type: "SECONDARY";
executableUser: {
entities: ExecutableUserEntityForParameter[];
};
}
);
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discriminated union for ActionForParameter has a logical flaw. When type is optional on line 94 (type?: "PRIMARY"), it creates ambiguity: if type is undefined, TypeScript cannot determine which union branch applies. This breaks the discriminated union pattern and could allow objects without type or executableUser to pass type checking. Consider making type required for both branches (remove the ? on line 94) to maintain proper type discrimination, or restructure to explicitly handle the case where type is omitted (e.g., by making it a three-way union with an explicit branch for { type?: undefined }).

Copilot uses AI. Check for mistakes.
Copy link
Member

@tasshi-me tasshi-me left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: rest-api-client @kintone/rest-api-client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants